package com.atguigu.controller;

import com.atguigu.cache.ShopCache;
import com.atguigu.entity.BaseCategoryView;
import com.atguigu.entity.ProductSalePropertyKey;
import com.atguigu.entity.SkuInfo;
import com.atguigu.result.RetVal;
import com.atguigu.service.BaseCategory3Service;
import com.atguigu.service.BaseCategoryViewService;
import com.atguigu.service.SkuDetailService;
import com.atguigu.service.SkuInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import rx.internal.util.unsafe.MpmcArrayQueue;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/sku")
public class SkuDetailController {
    @Autowired
    private SkuDetailService skuDetailService;
    @Autowired
    private SkuInfoService skuInfoService;
    @Autowired
    private BaseCategoryViewService categoryViewService;

    //根据skuid查询skuInfo信息
    @ShopCache(prefix = "sku:info:")
    @GetMapping("/getSkuInfo/{skuId}")
    public SkuInfo getSkuInfo(@PathVariable Long skuId){
        SkuInfo skuInfo = skuDetailService.getSkuInfo(skuId);
        return skuInfo;
    }
    //根据productId skuId 获取所有spu商品属性对应的某个sku的商品销售属性  在前端默认为勾选状态
    @GetMapping("/getSpuSaleProperty/{productId}/{skuId}")
    public List<ProductSalePropertyKey> getSpuSaleProperty(@PathVariable Long productId,
                                                           @PathVariable Long skuId){
       return skuDetailService.getSpuSaleProperty(productId,skuId);
    }
    //根据skuId查询商品实时价格
    @GetMapping("/getSkuPrice/{skuId}")
    public BigDecimal getSkuPrice(@PathVariable Long skuId){
        SkuInfo skuInfo = skuInfoService.getById(skuId);
        return skuInfo.getPrice();
    }
    //根据skuId查询分类信息
    @GetMapping("/getCategoryView/{category3Id}")
    public BaseCategoryView getCategoryView(@PathVariable Long category3Id){
        return categoryViewService.getById(category3Id);
    }
    //通过某个skuId获取与之对应的商品销售属性关系 例:24 45|48 用于选择商品版本或者颜色时 进行页面更换
    @ShopCache(prefix = "sku:skuSalePropertyValueId:")
    @GetMapping("/getSkuSalePropertyValueId/{productId}")
    public Map getSkuSalePropertyValueId(@PathVariable Long productId){
        return skuDetailService.getSkuSalePropertyValueId(productId);
    }


}
